use "liss_panel.dta", replace

/*demographic variables*/
gen female = geslacht
recode female 2=1 1=0
gen age10 = leeftijd/10
gen educ = (oplcat-1)/5
gen incquint = brutohh_f
recode incquint min/2527=0 2527.1/3534=.25 3534.1/4475=.5 4475.1/5902=.75 5902.1/max=1 
gen lrself_10 = cv10c101/10
recode lrself_10 2/max=. .=.
gen lrself_10nm = lrself_10
recode lrself_10nm .=5
gen loinc = 0
recode loinc *=1 if incquint <.25
gen hiinc = 0
recode hiinc *=1 if incquint >.75


/*party choice 2017
cv18j307 is "For which party did you vote in the parliamentary elections of 15 March 2017?" 
*/
gen ptyvt_17 = cv18j307 
recode ptyvt_17 1=1 2=2 3=3 4=4 5=5 6=6 7=7 8=8 9=9 10=9 11=8 12=9 13=9 14=. 15=9 998=. 999=.
label define ptyvt_17 1 "VVD" 2 "PVV" 3 "CDA" 4 "D66" 5 "GL" 6 "SP" 7 "PvdA" 8 "CUSGP" 9 "other", replace
label values ptyvt_17 ptyvt_17


/*econ satisfaction and confidence*/
gen econsat_10 = cv10c043/10
recode econsat_10 2/max=. .=.
gen econcnf_10 = cv10c026/10
recode econcnf_10 2/max=. .=.
gen econsat_17 = cv17i043/10
recode econsat_17 2/max=. .=.
gen econcnf_17 = cv17i026/10
recode econcnf_17 2/max=. .=.
gen econper_10 = (econsat_10 + econcnf_10)/2
gen econper_17 = (econsat_17 + econcnf_17)/2

/*Results reported in Table 4 and figure 3*/
mlogit ptyvt_17 econper_17 econper_10 lrself_10nm female age10 educ loinc hiinc, b(1)
gen econper_17i = econper_17*-1+1
qui mlogit ptyvt_17 econper_17i econper_10 lrself_10nm female age10 educ loinc hiinc, b(1)
margins, dydx(econper_17i) at(econper_10=(0(.1)1)) predict(outcome(1))
marginsplot, yline(0, lc(gs11) lpattern(dash)) ylabel(-.5(.25).5) recast(line) recastci(rarea) scheme(s1mono) graphregion(fcolor(white) ifcolor(white)) xtitle("Economic Situation 2010") ///
            ytitle("Effect of neg. econ. shift") title("A. VVD") ciopt(color(%20)) level(95) name(vvdfd2, replace)
margins, dydx(econper_17i) at(econper_10=(0(.1)1)) predict(outcome(2))
marginsplot, yline(0, lc(gs11) lpattern(dash)) ylabel(-.5(.25).5) recast(line) recastci(rarea) scheme(s1mono) graphregion(fcolor(white) ifcolor(white)) xtitle("Economic Situation 2010") ///
            ytitle("Effect of neg. econ. shift") title("D. PVV") ciopt(color(%20)) level(95) name(pvvfd2, replace)
margins, dydx(econper_17i) at(econper_10=(0(.1)1)) predict(outcome(3))
marginsplot, yline(0, lc(gs11) lpattern(dash)) ylabel(-.5(.25).5) recast(line) recastci(rarea) scheme(s1mono) graphregion(fcolor(white) ifcolor(white)) xtitle("Economic Situation 2010") ///
            ytitle("Effect of neg. econ. shift") title("C. CDA") ciopt(color(%20)) level(95) name(cdafd2, replace)
			margins, dydx(econper_17i) at(econper_10=(0(.1)1)) predict(outcome(7))
marginsplot, yline(0, lc(gs11) lpattern(dash)) ylabel(-.5(.25).5) recast(line) recastci(rarea) scheme(s1mono) graphregion(fcolor(white) ifcolor(white)) xtitle("Economic Situation 2010") ///
            ytitle("Effect of neg. econ. shift") title("B. PvdA") ciopt(color(%20)) level(95) name(pvdafd2, replace)
graph combine vvdfd2 pvdafd2 cdafd2 pvvfd2, scheme(s1mono) ycommon 

/*other challenger parties - figure A3 in SI*/	
qui mlogit ptyvt_17 econper_17i econper_10 lrself_10nm female age10 educ loinc hiinc, b(1)
margins, dydx(econper_17i) at(econper_10=(0(.1)1)) predict(outcome(4))
marginsplot, yline(0, lc(gs11) lpattern(dash)) ylabel(-.5(.25).5) recast(line) recastci(rarea) scheme(s1mono) graphregion(fcolor(white) ifcolor(white)) xtitle("Economic Situation 2010") ///
            ytitle("Effect of neg. econ. shift on vote") title("A. D66") ciopt(color(%20)) level(95) name(d66fd2, replace)		
margins, dydx(econper_17i) at(econper_10=(0(.1)1)) predict(outcome(5))
marginsplot, yline(0, lc(gs11) lpattern(dash)) ylabel(-.5(.25).5) recast(line) recastci(rarea) scheme(s1mono) graphregion(fcolor(white) ifcolor(white)) xtitle("Economic Situation 2010") ///
            ytitle("Effect of neg. econ. shift on vote") title("B. GL") ciopt(color(%20)) level(95) name(glfd2, replace)
margins, dydx(econper_17i) at(econper_10=(0(.1)1)) predict(outcome(6))
marginsplot, yline(0, lc(gs11) lpattern(dash)) ylabel(-.5(.25).5) recast(line) recastci(rarea) scheme(s1mono) graphregion(fcolor(white) ifcolor(white)) xtitle("Economic Situation 2010") ///
            ytitle("Effect of neg. econ. shift on vote") title("C. SP") ciopt(color(%20)) level(95) name(spfd2, replace)					
margins, dydx(econper_17i) at(econper_10=(0(.1)1)) predict(outcome(8))
marginsplot, yline(0, lc(gs11) lpattern(dash)) ylabel(-.5(.25).5) recast(line) recastci(rarea) scheme(s1mono) graphregion(fcolor(white) ifcolor(white)) xtitle("Economic Situation 2010") ///
            ytitle("Effect of neg. econ. shift on vote") title("D. CUSGP") ciopt(color(%20)) level(95) name(cusgpfd2, replace)			
margins, dydx(econper_17i) at(econper_10=(0(.1)1)) predict(outcome(9))
marginsplot, yline(0, lc(gs11) lpattern(dash)) ylabel(-.5(.25).5) recast(line) recastci(rarea) scheme(s1mono) graphregion(fcolor(white) ifcolor(white)) xtitle("Economic Situation 2010") ///
            ytitle("Effect of neg. econ. shift on vote") title("E. Other") ciopt(color(%20)) level(95) name(ofd2, replace)			
graph combine d66fd2 glfd2 spfd2 cusgpfd2 ofd2, scheme(s1mono) ycommon		
			
